﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using crm_dal.Objects;
using core_services.WCF.Base;
using System.Runtime.Serialization;

namespace core_services.WCF.SalesReport
{
	[DataContractAttribute]
	public class SalesReportFilter : ServiceFilter<Sale>
	{
		public SalesReportFilter() 
		{
			UserID = -1;
		}

		[DataMember(EmitDefaultValue=true)]
		private DateTime _from;
		public DateTime From
		{
			get
			{
				if(_from == null) return DateTime.MinValue;
				else return _from;
			}
			set
			{
				_from = value;
			}
		}

		[DataMember(EmitDefaultValue = true)]
		private DateTime _to;
		public DateTime To
		{
			get
			{
				if(_to == null) return DateTime.MaxValue;
				else return _to;
			}
			set
			{
				_to = value;
			}
		}

		[DataMember(EmitDefaultValue = true)]
		public int UserID{ get; set; }

		public override bool Matches(Sale sale)
		{
			if (sale.Date < From) return false;
			if (sale.Date > To) return false;
			if (UserID >= 0 && UserID != sale.UserID) return false;
			
			return true;
		}


	}
}
